package Vistas;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import Modelos.Categoria;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class FrmCategoria extends javax.swing.JFrame {
	private JLabel LblNombre;
	private JTextField TxtCategoria;
	private JLabel LblCodigo;
	private JButton BtnSalir;
	private JButton BtnCancelar;
	private JButton BtnGuardar;
	private JTextField TxtNombre;

	/**
	* Auto-generated main method to display this JFrame
	*/
	
	
	public boolean Validar(){
		return !TxtNombre.getText().equals("");
	}
	
	public Categoria CreateCategoria(){
		return new Categoria(Integer.valueOf(TxtCategoria.getText()),TxtNombre.getText());
	}
	
	public void Limpiar(){
		TxtNombre.setText("");
	}
	
	public void MsgError(){
		JOptionPane.showMessageDialog(rootPane,"Datos Invalidos");
	}
	
	public void AsignarCodigoCategoria(int n){
		TxtCategoria.setText(String.valueOf(n+1));
	}
	
	public void MensajeSalir(){
		JOptionPane.showMessageDialog(rootPane,"No se ha podido registrar ninguna categoria");
	}
	
	public FrmCategoria() {
		super();
		initGUI();
		TxtCategoria.setEnabled(false);
	}
	
	public void MensajeExito(){
		JOptionPane.showMessageDialog(rootPane,"Operacion Completada");
	}
	
	public void addListener(ActionListener actionlistener){
		BtnCancelar.addActionListener(actionlistener);
		BtnGuardar.addActionListener(actionlistener);
		BtnSalir.addActionListener(actionlistener);
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				LblNombre = new JLabel();
				getContentPane().add(LblNombre);
				LblNombre.setText("Nombre Categoria");
				LblNombre.setBounds(19, 69, 108, 25);
			}
			{
				TxtNombre = new JTextField();
				getContentPane().add(TxtNombre);
				TxtNombre.setBounds(132, 71, 137, 21);
			}
			{
				BtnGuardar = new JButton();
				getContentPane().add(BtnGuardar);
				BtnGuardar.setText("Guardar");
				BtnGuardar.setBounds(19, 122, 92, 21);
			}
			{
				BtnCancelar = new JButton();
				getContentPane().add(BtnCancelar);
				BtnCancelar.setText("Cancelar");
				BtnCancelar.setBounds(122, 122, 102, 21);
			}
			{
				BtnSalir = new JButton();
				getContentPane().add(BtnSalir);
				BtnSalir.setText("Salir");
				BtnSalir.setBounds(328, 118, 64, 21);
			}
			{
				LblCodigo = new JLabel();
				getContentPane().add(LblCodigo);
				LblCodigo.setText("Codigo Categoria");
				LblCodigo.setBounds(19, 28, 108, 14);
			}
			{
				TxtCategoria = new JTextField();
				getContentPane().add(TxtCategoria);
				TxtCategoria.setBounds(132, 25, 137, 21);
			}
			pack();
			this.setSize(423, 197);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
